-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
exit_early #114
base: testnet-2
Are you sure you want to change the base?
exit_early #114
Conversation
stylus-sdk/src/evm.rs
Outdated
/// Exits program execution early with the given status code. | ||
/// If `0`, the program returns successfully with any data supplied by `write_result`. | ||
/// Otherwise, the program reverts and treats any `write_result` data as revert data. | ||
#[inline] | ||
pub fn exit_early(status: u32) { | ||
unsafe { hostio::exit_early(status) } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of exposing this as-is to users, let's add a revert!
macro that expands to a console!
, write_result
and early_exit()
. Also let's go through the SDK and find places where we can replace panics with it.
We'll also want an affordance for the success case, which should ideally take an arguement for the return data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this macro. Note that exit_early
does need to still be public so that it can be called by the expanded macro. I also added a similar succeed
macro.
Currently the macro does not call write_result
- it seemed awkward to me that the macro would receive both a result slice for revert data and a message to print. The user can first call output
. However, if you do prefer the macro handle both (presumably just called as revert!(slice_data, "Some console message")
, let me know and I'll make that change.
1eee40d
to
03baad7
Compare
03baad7
to
0b7a5db
Compare
0b7a5db
to
a4fe654
Compare
a4fe654
to
47879f0
Compare
Parent PR: OffchainLabs/stylus#208
Associated PR: OffchainLabs/stylus-sdk-c#18
Stylus update PR: OffchainLabs/stylus#210
Closes STY-39